<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script src="./js/jquery-1.9.1.js"></script>
<script src="./ibsheet/ibsheetinfo.js"></script>
<script src="./ibsheet/ibsheet.js"></script>
<script>
	$(document).ready(function() {
	});
	
	var sheetIdx = 1;
	function createSheet() {
		var sheetName = "mySheet" + sheetIdx;
		
		var view = document.getElementById("viewArea");
		var div= document.createElement('div'); //div 생성
		div.setAttribute("id", "view_" + sheetName);
		
		view.appendChild(div);
		
		createIBSheet2(document.getElementById("view_" + sheetName), sheetName,"100%","200px");
		var sheetobj = window[sheetName];
		
		loadSheet(sheetobj);
		
		sheetIdx++;		// 시트 생성 후, 
	}
	
	function loadSheet(sheet) {
		
		var cfg = {SearchMode:smLazyLoad, Page:30};
		var headers = [
			{Text:"모델번호|평형|단가(A)|판매가(B)\nA * 1.03 / 100|현금구입가(C)\n A * 0.9 / 100|할부구입가(D)\nA * 0.93 / 100|현금부담액\nB-C|할부부담액\nB-D", Align:"Center"}
		];
		var info = {Sort:1,ColMove:1,ColResize:1,HeaderCheck:0};
		var cols = [
			{Type:"Text",Width:130},
			{Type:"Text",Width:100,ColMerge:0},
			{Type:"Int",Width:80,SaveName:"A", Align:"Right",ColMerge:0},
			{Type:"AutoSum",Width:85,SaveName:"B",Format:"#,##0.00",CalcLogic:"|A|*1.03/100", Align:"Right",ColMerge:0},
			{Type:"AutoSum",Width:85,SaveName:"C",Format:"#,##0.00",CalcLogic:"|A|*0.9/100", Align:"Right",ColMerge:0},
			{Type:"AutoSum",Width:85,SaveName:"D",Format:"#,##0.00",CalcLogic:"|A|*0.93/100", Align:"Right",ColMerge:0},
			{Type:"AutoAvg",Width:85,Format:"#,##0.00",CalcLogic:"|B|-|C|", ColMerge:1, Align:"Right",ColMerge:0},
			{Type:"AutoAvg",Width:85,Format:"#,##0.00",CalcLogic:"|B|-|D|", Align:"Right",ColMerge:0}
		];

		sheet.SetConfig(cfg);
		sheet.InitHeaders(headers,info);
		sheet.InitColumns(cols);
		
		sheet.DoSearch("./data/dynamic_data" + (sheetIdx % 3 + 1) + ".xml");

		sheet.FitColWidth();
	}

	/*Sheet 각종 처리*/
	function doAction(sAction) {
		
		switch(sAction) {
			case "search":		//조회
				mySheet.DoSearch("../data/sheet_data.xml");
				break;
				
			case "reload":		//초기화
				mySheet.RemoveAll();
				break;
		}
	}
	
	function mySheet_OnSearchEnd() {
		mySheet.FitColWidth();
	}
</script>
<title>동적 시트 생성</title>
</head>
<body>
<div id="main">
	<div id="title">동적 시트 생성 예제</div>

	<div id="functionArea">
		<input type="button" value="적용" onclick="createSheet()"> 버튼을 누르면 시트가 계속 추가된다.
	</div>
	
	<div id="viewArea">
	</div>
</div>
</body>
</html>